﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using tfs = Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using System.Configuration;
using AgileDashboard.Entities;
using AutoMapper;
using AgileDashboard.Data;
using AgileDashboard.Services.Helpers;

namespace AgileDashboard.Services
{
    public class TfsDataLoaderService
    {

        public TfsDataLoader DataLoader { get; set; }

                private WorkItemDataSource workItemDataSource { get; set; }
        private QueryDataSource queryDataSource { get; set; }



        public TfsDataLoaderService()
        {
            DataLoader = new TfsDataLoader();
            workItemDataSource = new WorkItemDataSource();
            queryDataSource = new QueryDataSource();
        }


        public TfsDataLoaderService(TfsDataLoader dataLoader)
        {
            DataLoader = dataLoader;
        }


        public List<TfsProject> GetTeamProjects()
        {
            List<TfsProject> projects = new List<TfsProject>();

            tfs.ProjectCollection projCollection = DataLoader.GetAllTeamProjects();

            foreach (tfs.Project proj in projCollection)
            {
                projects.Add(ConverterHelpers.ConvertProject(proj));
            }

            return projects;
        }


        public TfsProject GetProjectByName(string name)
        {
            return ConverterHelpers.ConvertProject(DataLoader.GetTeamProjectByName(name));

        }


        public List<TfsQuery> GetQueries(int projectId)
        {
            tfs.Project proj = DataLoader.GetTeamProjectById(projectId);

            return queryDataSource.GetQueries(proj);

        }





    }
}
